package com.benjamin.common;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;

public class FileUtils {
	
	public String readFile(Context ctx, String fileName) throws IOException {
		FileInputStream inputStream = null;
		StringBuilder sb = new StringBuilder();

		try {
			try {
				inputStream = ctx.openFileInput(fileName);
				
				InputStreamReader reader = new InputStreamReader(inputStream);
				BufferedReader bufReader = new BufferedReader(reader);
				
				String str;
				while ((str = bufReader.readLine()) != null) {
					sb.append(str + "\n");
				}
				
				bufReader.close();
				reader.close();				
			} finally {
				if (inputStream != null) {
					inputStream.close();
				}
			}
		} catch (IOException ioe) {
			android.util.Log.e("FileUtils", ioe.toString(), ioe);
			throw ioe;
		}
		
		return sb.toString();
	}
}
